<?php
/**
 * Created by PhpStorm.
 * User: yzapple
 * Date: 2018/1/25
 * Time: 上午9:50
 */

namespace app\common\model;


class Article extends Base
{

    protected $table = "article";



    public $base_arr = [
        'table' => 'article',
        'field' => 'content,is_deleted,type',
        'primary_key' => 'id'
    ];

    public $attach_arr =  [


    ];


    /**
     * 获取字段对应的数组
     * */
    public function getDataByMysql(){
        $data = [
            't_name' => $this->table,//必填
            'model' => '文章',//必填
            'content' => '文章内容',
            'type'=> '{"1":"用户指南","2":"关于我们","3":"影像使用指南"}',
            'is_deleted' => '{"2":"功能禁用","1":"功能启用","3":"功能删除"}'
        ];
        return $data;
    }


    /**
     * 获取日志的访问方法
     **/
    public static function addArticleAdminLog($list_action='',$form_data=[],$userId,$admin_type){
        $model = new Article();
        $actionName = strtolower(ACTION_NAME);
        $controller = strtolower(CONTROLLER_NAME);
        $old_data = [];
        $type = '';
        $url = $controller.'/'.$list_action;

        switch($actionName){


            case "add_article":
                $type = 'add';
                if ($model->request->isPost()) {

                }

                break;
            case "edit_article":
                $type = 'edit';
                if ($model->request->isPost()) {
                    $old_data = Base::getOneOldDataByTables($form_data['aid'],$model->base_arr,$model->attach_arr);
                    $form_data['id']=$form_data['aid'];

                }
                break;

        }


        if($model->request->isPost() ){

            //$model 实例化之后的模型
            //$type 数据的操作类型
            //$form_data  form表单提交之后的表单
            //$url 跳转路径
            //$old_data 原有的数据
            //$attach_arr 附属表单数组
            //$primary_key 基本表单的主键值id
            $result =  Base::operaTable($model,$userId,$type,$form_data,$url,$old_data,$model->attach_arr,'id',$admin_type);

            return $result;
        }


        return true;


    }


}
